/**
 * Created by BAGATAMA on 2015/8/28.
 */
function Dictionary(map) {
    this.data = map;
    this.get = function (key) {
        return this.data[key];
    };
    this.size = function () {
        var i = 0;
        for (var j in this.data) {
            i++;
        }
        return i;
    }
    this.setMapData = function (map){
        this.data = map;
    }
    this.setListData = function (list){
        for (var i = 0 ; i < list.length; i++){
            this.data.i = list[i];
        }
    }
    this.toString = function(){
        var str = '{';
        for (var i in this.data){
            str += i +':' + this.data[i] + ', ';
        }
        str += '}';
        return str;
    }

}

function ObjQuery(){
    var arr = [];
    this.findById = function(id, arr){
        this.arr = arr;
        for (var i in arr){
            if (arr[i].id == id){
                return parseInt(i);
            }
        }
        return -1;
    }
}

var format = function(time, format){
    var t = new Date(time);
    var tf = function(i){return (i < 10 ? '0' : '') + i};
    return format.replace(/yyyy|MM|dd|HH|mm|ss/g, function(a){
        switch(a){
            case 'yyyy':
                return tf(t.getFullYear());
                break;
            case 'MM':
                return tf(t.getMonth() + 1);
                break;
            case 'mm':
                return tf(t.getMinutes());
                break;
            case 'dd':
                return tf(t.getDate());
                break;
            case 'HH':
                return tf(t.getHours());
                break;
            case 'ss':
                return tf(t.getSeconds());
                break;
        }
    })
}

function DateDiff(later, earlier){    //yyyy-MM-dd
    var oDate1  =  new Date(later);
    var oDate2  =  new Date(earlier);
    var iDays  =  parseInt(Math.abs(oDate1  -  oDate2)  /  1000  /  60  /  60  /24);  //把相差的毫秒数转换为天数
    return  iDays;
}